﻿@using Himall.Core;
@model Himall.Web.Areas.SellerAdmin.Models.ShopProfileStep1
<script type="text/javascript">
    var refusereason = "@(ViewBag.RefuseReason)";
</script>
<link rel="stylesheet" type="text/css" href="~/Content/bootstrap-datetimepicker.min.css">
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <li class="active"><a>公司信息</a></li>
        <div class="process-step">
            <span class="odd">公司信息</span>
            <i class="glyphicon glyphicon-arrow-right"></i>
            <span>财务信息</span>
            <i class="glyphicon glyphicon-arrow-right"></i>
            <span>店铺信息</span>
            <i class="glyphicon glyphicon-arrow-right"></i>
            <span>审核状态</span>
        </div>
    </ul>

    <form class="form-horizontal form-pt0" role="form" id="form_step1">
        <h3 class="table-hd">公司及联系人信息</h3>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>公司名称：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.CompanyName, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.CompanyName)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>公司所在地：</label>
            <div class="col-sm-5">
                <select id="companyLocationProvince" class="form-control input-sm select-sort"><option></option></select>
                <select id="companyLocationCity" class="form-control input-sm select-sort"><option></option></select>
                <select id="companyLocationDistrict" class="form-control input-sm select-sort"><option></option></select>
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.CityRegionId)
            </div>
            @Html.TextBoxFor(item => item.CityRegionId, new { style = "width:0px;height:0px;border-width:0px;" })
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>公司详细地址：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.Address, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.Address)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>公司电话：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.Phone, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.Phone)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>员工总数：</label>
            <div class="col-sm-3">

                @Html.DropDownListFor(item => item.EmployeeCount, (IEnumerable<SelectListItem>)Himall.Model.CompanyEmployeeCount.LessThanFive.ToSelectList(), new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.EmployeeCount)
            </div>
        </div>
    
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>联系人姓名：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.ContactName, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.ContactName)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>联系人电话：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.ContactPhone, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.ContactPhone)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>电子邮箱：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.Email, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.Email)
            </div>
        </div>
        <h3 class="table-hd">营业执照信息（副本）</h3>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>营业执照号：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.BusinessLicenceNumber, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.BusinessLicenceNumber)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>营业执照所在地：</label>
            <div class="col-sm-5">
                <select id="BusinessLicenceLocationProvince" class="form-control input-sm select-sort"><option></option></select>
                <select id="BusinessLicenceLocationCity" class="form-control input-sm select-sort"><option></option></select>
                <select id="BusinessLicenceLocationDistrict" class="form-control input-sm select-sort"><option></option></select>
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.BusinessLicenceArea)
            </div>
            @Html.TextBoxFor(item => item.BusinessLicenceArea, new { style = "width:0px;height:0px;border-width:0px;" })
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>营业执照有效期：</label>
            <div class="col-sm-5">
                <div class="row">
                    <div class="col-sm-6">
                        <input type="text" id="BusinessLicenceValidStart" name="BusinessLicenceValidStart" class="form-control input-sm start_datetime" value="@(Model.BusinessLicenceValidStart.Year != 1 ? Model.BusinessLicenceValidStart.ToString("yyyy-MM-dd") : "")" />
                        <i class="glyphicon glyphicon-calendar"></i>
                    </div>
                    <div class="col-sm-6">
                        <input type="text" id="BusinessLicenceValidEnd" name="BusinessLicenceValidEnd" class="form-control input-sm end_datetime" value="@(Model.BusinessLicenceValidEnd.Year != 1 ? Model.BusinessLicenceValidEnd.ToString("yyyy-MM-dd") : "")" />
                        <i class="glyphicon glyphicon-calendar"></i>
                    </div>

                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>法定经营范围：</label>
            <div class="col-sm-5">
                @Html.TextAreaFor(item => item.BusinessSphere, new { @class = "form-control input-sm", maxLength="100" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.BusinessSphere)
            </div>
        </div>
        <div class="form-group upload-img " id="businessLicenceNumberPhoto"></div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>注册资金：</label>
            <div class="col-sm-3">
                @(Html.TextBoxFor(item => item.RegisterMoney, new { @class = "form-control input-sm" }))
            </div>
            <div class="col-sm-1" style="line-height:30px">万元</div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.RegisterMoney)
            </div>
        </div>

        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>公司法定代表人：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.legalPerson, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.legalPerson)
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>公司成立日期：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.CompanyFoundingDate, new { @class = "form-control input-sm receipt_datetime", Value = (Model.CompanyFoundingDate.Year != 1 ? Model.CompanyFoundingDate.ToString("yyyy-MM-dd") : "") })
                <i class="glyphicon glyphicon-calendar"></i>
             
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.CompanyFoundingDate)
            </div>
        </div>

        <div class="form-group">
            <label for="" class="col-sm-2 control-label"><b>*</b>组织机构代码：</label>
            <div class="col-sm-3">
                @Html.TextBoxFor(item => item.OrganizationCode, new { @class = "form-control input-sm" })
            </div>
            <div class="col-sm-3">
                @Html.ValidationMessageFor(item => item.OrganizationCode)
            </div>
        </div>
        <div class="form-group upload-img " id="organizeCodePhoto"></div>
        <div class="form-group upload-img " id="BusinessLicenseCert"></div>
        <div class="form-group upload-img " id="ProductCert"></div>
        <div class="form-group upload-img " id="OtherCert"></div>

        <h3 class="table-hd">一般纳税人证明 <span class="cor-red">注：所属企业具有一般纳税人证明时，此项为必填。</span></h3>
        <div class="form-group upload-img " id="generalTaxpayerPhoto"></div>

        <div class="form-group" style="padding:20px 0 200px">
            <div class="col-sm-offset-2 col-sm-10">
                <!--<button type="submit" class="btn btn-primary">下 一 步</button>-->
                <a class="btn btn-primary" id="nextStep" href="javascript:;">下 一 步</a>
            </div>
        </div>
    </form>
</div>
<script src="~/Scripts/Region.js"></script>
<script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.zh-CN.js"></script>
@*<script src="~/Scripts/jquery.himallUpload.js"></script>*@
<script src="~/Scripts/jquery.hishopUpload.js"></script>
<script src="~/Scripts/jquery.himallLinkage.nocreate.js"></script>
<script src="~/Scripts/autoNumeric.js"></script>
<script type="text/javascript">
    $(function () {
        if (refusereason.length > 0) {
            $.dialog({
                title: '申请被拒绝，原因如下',
                lock: true,
                id: 'refusertips',
                width: '400px',
                content: '<div style="font-size:14px;color:red;">'+refusereason+'</div>',
                padding: '20px 10px',
                ok: function () { }
            });
        }

        $(".start_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            weekStart: 1,
            minView: 2
        });
        $(".end_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            weekStart: 1,
            minView: 2
        });
        $(".receipt_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            weekStart: 1,
            minView: 2
        });
        /*$(".start_datetime").click(function() {
			$('.end_datetime').datetimepicker('show');
		});
		$(".end_datetime").click(function() {
			$('.start_datetime').datetimepicker('show');
		});*/

        $('.start_datetime').on('changeDate', function () {
            if ($(".end_datetime").val()) {
                if ($(".start_datetime").val() > $(".end_datetime").val()) {
                    $('.end_datetime').val($(".start_datetime").val());
                }
            }

            $('.end_datetime').datetimepicker('setStartDate', $(".start_datetime").val());
        });


        $('#nextStep').click(function () {
            var form = $('#form_step1');
            if (form.valid()) {
                var bizNOPhoto = $('#businessLicenceNumberPhoto').hishopUpload('getImgSrc');
                var organizeCodePhoto = $('#organizeCodePhoto').hishopUpload('getImgSrc');
                var generalTaxpayerPhoto = $('#generalTaxpayerPhoto').hishopUpload('getImgSrc');

                var businessLicenceValidStart = $('#BusinessLicenceValidStart').val();
                var businessLicenceValidEnd = $('#BusinessLicenceValidEnd').val();

                if (!isSelectAddr($('#companyLocationProvince'), $('#companyLocationCity'), $('#companyLocationDistrict')))
                    $.dialog.errorTips('请选择公司所在地');
                else if (!isSelectAddr($('#BusinessLicenceLocationProvince'), $('#BusinessLicenceLocationCity'), $('#BusinessLicenceLocationDistrict')))
                    $.dialog.errorTips('请选择营业执照所在地');
                else if (!bizNOPhoto)
                    $.dialog.errorTips('请上传营业执照号电子版');
                else if (!organizeCodePhoto)
                    $.dialog.errorTips('请上传组织机构代码证电子版');
                else if (!generalTaxpayerPhoto)
                    $.dialog.errorTips('请上传一般纳税人证明');
                else if (!businessLicenceValidStart)
                    $.dialog.errorTips('请选择营业执照起始有效期');
                else if (!businessLicenceValidEnd)
                    $.dialog.errorTips('请选择营业执照终止有效期');
                else {
                    $('#RegisterMoney').val($('#RegisterMoney').val().replace(/,/g, ''));

                    var data = form.serialize();

                    var loading = showLoading();
                    $.post('EditProfile1', data, function (result) {
                        loading.close();
                        if (result.success)
                            window.top.location.href = "@(Url.Action("EditProfile2"))";
                        else
                            $.dialog.errorTips('保存失败！' + result.msg);
                    });
                }

            }
        });


        $('#businessLicenceNumberPhoto').hishopUpload({
            title: '<b>*</b>营业执照号电子版：',
            imageDescript: '请确保图片清晰，文字可辨并有清晰的红色公章。',
            displayImgSrc: '@Model.BusinessLicenceNumberPhoto',
            imgFieldName: "businessLicenceNumberPhoto",
            dataWidth: 6
        });

        $('#organizeCodePhoto').hishopUpload({
            title: '<b>*</b>组织机构代码证电子版：',
            imageDescript: '请确保图片清晰，文字可辨并有清晰的红色公章。',
            displayImgSrc: '@Model.OrganizationCodePhoto',
            imgFieldName: "OrganizationCodePhoto",
            dataWidth: 6
        });

        $('#generalTaxpayerPhoto').hishopUpload({
            title: '<b>*</b>一般纳税人证明：',
            imageDescript: '请确保图片清晰，文字可辨并有清晰的红色公章。',
            displayImgSrc: '@Model.GeneralTaxpayerPhoto',
            imgFieldName: "GeneralTaxpayerPhoto",
            dataWidth: 6
        });

        $("#BusinessLicenseCert").hishopUpload({
            title: '经营许可类证书:(最多三张)',
            imageDescript: '',
            displayImgSrc: '@Model.BusinessLicenseCert',
            imgFieldName: "BusinessLicenseCert",
            defaultImg: '/Images/default_100x100.png',
            imagesCount: 3,
            dataWidth: 6
        });
        $("#ProductCert").hishopUpload({
            title: '产品类证书:(最多三张)',
            imageDescript: '',
            displayImgSrc: '@Model.ProductCert',
            imgFieldName: "ProductCert",
            defaultImg: '/Images/default_100x100.png',
            imagesCount: 3,
            dataWidth: 6
        });
        $("#OtherCert").hishopUpload({
            title: '其它证书:(最多三张)',
            imageDescript: '',
            displayImgSrc: '@Model.OtherCert',
            imgFieldName: "OtherCert",
            defaultImg: '/Images/default_100x100.png',
            //pictureSize: '100*100',
            imagesCount: 3,
            dataWidth: 6
        });


        $('#companyLocationProvince,#companyLocationCity,#companyLocationDistrict').himallLinkage({//公司所在地
            url: '/common/RegionAPI/GetRegion',
            enableDefaultItem: true,
            defaultItemsText: '请选择',
            defaultSelectedValues: [@ViewBag.CompanyRegionIds],
            onChange: function (level, value, text) {
                var len = $("#companyLocationDistrict option").size();
                if (level == 1 && len == 0) {
                    $('input[name="CityRegionId"]').val(value);
                }
                else if (level == 2)
                    $('input[name="CityRegionId"]').val(value);
            }
        });


        $('#BusinessLicenceLocationProvince,#BusinessLicenceLocationCity,#BusinessLicenceLocationDistrict').himallLinkage({//营业执照所在地
            url: '/common/RegionAPI/GetRegion',
            enableDefaultItem: true,
            defaultItemsText: '请选择',
            defaultSelectedValues: [@ViewBag.BusinessLicenceRegionIds],
            onChange: function (level, value, text) {
                var len = $("#BusinessLicenceLocationDistrict option").size();
                if (level == 1 && len == 0)
                    $('input[name="BusinessLicenceArea"]').val(value);
                else if (level == 2)
                    $('input[name="BusinessLicenceArea"]').val(value);
            }
        });
        //$('#RegisterMoney').autoNumeric({vMax:999999});
    });

    var isSelectAddr = function (p, c, t) {
        if (!p || !c || !t)
            return false;
        var haveProvince = false;
        var haveCity = false;
        var haveTown = false;
        p.children().each(function (i, e) {
            s = e.selected;
            if (s == true && i > 0) {
                haveProvince = true;
                return;
            }
        });
        if (haveProvince) {
            c.children().each(function (i, e) {
                s = e.selected;
                v = e.value;
                if (s == true && v != "") {
                    haveCity = true;
                    return;
                }
            });
            if (haveCity) {
                var idx = 0;
                t.children().each(function (i, e) {
                    s = e.selected;
                    v = e.value;
                    idx = i;
                    if (s == true && v != "") {
                        haveTown = true;
                        return;
                    }
                });
                haveTown = idx > 0 ? haveTown : true;
            }
        }
        return haveProvince && haveCity && haveTown;
    };
</script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
